<template style="background: white">
	<view>
		<view class="index-content">

			<view class="index-coupon has-bg-white has-pd-10 top_30">
				<view class="goods-list" v-if="couponlist.length > 0">
					<view class="" v-if="type==33">
						<orange-goods-card-home-three v-for="(item,index) in couponlist" :index='index' :tkmoney='item.tkmoney' :tkmoneys='item.tkmoneys'
						 :itemid="item.skuId" :logo="jdlogo" :orangeprice='item.orangepricejd' :isEnable='isEnable' :is-invitation="isInvitation"
						 :itempic="item.itempic" :itemtitle="item.skuName" :hours='item.hours'  :minute='item.minute'  :seconds='item.seconds'  :itemprice='item.itemprice'
						 :itemsale='item.itemsale' :itemendprice='""+item.itemendprice' :couponmoney="item.couponmoney" @success="clickItem"></orange-goods-card-home-three>
					</view>
					<view class="" v-else>
						<orange-goods-card-home v-for="(item,index) in couponlist" :index='index' :tkmoney='item.tkmoney' :tkmoneys='item.tkmoneys'
						 :itemid="item.skuId" :logo="jdlogo" :isEnable='isEnable' :is-invitation="isInvitation" :itempic="item.itempic"
						 :itemtitle="item.skuName" :itemprice='"¥"+item.itemprice' :itemsale='item.itemsale' :itemendprice='""+item.itemendprice'
						 :couponmoney="item.couponmoney" @success="clickItem"></orange-goods-card-home>
					</view>




				</view>
			</view>
			<!-- 悬浮上拉 -->
			<view class="scroll_top" @tap="topScrollTap" v-bind:class="[scrollTop ? 'active' : '','']" style="bottom: 56px;">
				<text class="iconfont icon-shangla"></text>
			</view>
			<!-- 加载更多提示 -->
			<view class="s-col is-col-24" v-if="couponlist.length > 0">
				<load-more :loadingType="loadingType" :contentText="contentText"></load-more>
			</view>
			<!-- 加载更多提示 -->
			<empty v-if="couponlist.length === 0" des="暂无数据" show="false"></empty>
		</view>
	</view>
</template>

<script>
	export default {
		onShareAppMessage(res) {
			return {
				title: '购物先领券，一年省一半',
				path: '/pages/index/index'
			}
		},
		data() {
			return {
				logo: "../static/img/mao.png",
				taobao: "../static/img/taobao.png",
				isEnable: '否',
				jdlogo: "../static/img/jd.png",
				category: [
					'美食',
					'饮料',
					'婴儿',

					'纸巾',
					'洗衣液',
					'洗浴',
					'母婴',
					'湿巾',
					'车载',
				],
				TabCur: 0,
				TabCurs: 0,
				scrollLeft: 0,
				scrollLefts: 0,
				couponlist: [],
				page: 1,
				min_id: 1,
				cid: '休闲零食',
				type: 1,
				isInvitation: 0,
				sort: 4,
				genderKey: "gender",
				loadingType: 0,
				scrollTop: false,
				contentText: {
					contentdown: "上拉显示更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多数据了"
				}
			}
		},
		onLoad: function(e) {
			let a = this.$queue.getData("isEnable")
			if (a) {
				this.isEnable = a;
			}

			if (e.title && e.type) {
				if (e.type == -1) {
					this.type = 33
					uni.setNavigationBarTitle({
						title: e.title
					});
				} else {
					this.type = e.type;
					uni.setNavigationBarTitle({
						title: e.title
					});

				}
				this.loadCouponList();

			} else {
				uni.navigateBack()
			}
			uni.showLoading({
				title: '加载中...'
			});

			let userId = this.$queue.getData("userId");
			if (userId) {
				this.$Request.getT("/user/" + userId).then(res => {
					if (res.status === 0) {
						this.$queue.setData("image_url", res.data.image_url);
						this.$queue.setData("mobile", res.data.phone);
						this.isInvitation = res.data.isInvitation;
						this.$queue.setData("isInvitation", res.data.isInvitation);
						this.$queue.setData("relation", res.data.invitation);
						this.$queue.setData("grade", res.data.grade);
						this.$queue.setData("nickName", res.data.nickName);
						this.$queue.setData("relation_id", res.data.relationId);
						this.$queue.setData("gender", parseInt(res.data.gender));
					}
				});
			}
		},
		onPageScroll: function(e) {
			this.scrollTop = e.scrollTop > 200;
		},
		methods: {

			searchSelect(e) {
				this.TabCurs = e.currentTarget.dataset.id;
				this.sort = this.tab[e.currentTarget.dataset.id].jd;

				this.scrollLefts = (e.currentTarget.dataset.id - 1) * 60;
				this.page = 1;
				this.min_id = 1;
				uni.showLoading({
					title: '加载中...'
				});
				//#ifdef H5
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
				//#endif
				this.loadCouponList("Refresh");
			},
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id;
				this.cid = this.category[e.currentTarget.dataset.id];
				this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60;
				this.page = 1;
				this.min_id = 1;
				uni.showLoading({
					title: '加载中...'
				});
				//#ifdef H5
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
				//#endif
				this.loadCouponList("Refresh");
			},
			topScrollTap: function() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
			},
			clickItem(index) {
				this.$queue.setData("jd_list", JSON.stringify(this.couponlist[index]))
				uni.navigateTo({
					url: '/pages/detail/jd'
				});
			},
			loadCouponList: function(type) {
				this.loadingType = 1;
				this.$Request.getT('/jd/goods/eliteId/' + this.type + "/page/" + this.page + "/sortName/" + this.sort +
					"/sort/desc").then(
					res => {
						this.loadingType = 0;
						if (res.code === 200) {
							if (this.page === 1) {
								this.couponlist = [];
							}
							res.data.forEach(d => {
								let grade = this.$queue.getData("grade");
								if (d.imageInfo.imageList.length > 0) {
									d.itempic = d.imageInfo.imageList[0].url
								}
								if(this.type==33){
									let nowtime = (new Date()).getTime();
									d.hours = new Date(d.seckillInfo.seckillEndTime-nowtime).getHours()
									d.minutes = new Date(d.seckillInfo.seckillEndTime-nowtime).getMinutes()
									d.seconds = new Date(d.seckillInfo.seckillEndTime-nowtime).getSeconds()
									d.itemendprice = d.seckillInfo.seckillOriPrice
									d.orangepricejd = d.seckillInfo.seckillPrice
								}
								if(this.type!=33){
									d.itemendprice=d.priceInfo.price
								}
								
								console.log("shijisjfsa",d.hours)
								if (d.couponInfo.couponList.length > 0) {
									if (d.couponmoney = d.couponInfo.couponList[0].discount) {
										
									}
								} else {
									d.couponmoney = 0
								}
								d.tkmoneys = (d.commissionInfo.couponCommission * 0.9 * parseFloat(this.$queue.maxMoney())).toFixed(2);
								if (grade) {
									d.tkmoney = (d.commissionInfo.couponCommission * 0.9 * parseFloat(grade)).toFixed(2);
								} else {
									d.tkmoney = (d.commissionInfo.couponCommission * 0.9 * parseFloat(this.$queue.minMoney())).toFixed(2);
								}
								d.itemsale = d.inOrderCount30Days > 10000 ? "已售 " + (d.inOrderCount30Days / 10000).toFixed(1) + "万" : "已售 " +
									d.inOrderCount30Days;

								this.couponlist.push(d);


							})
						} else {
							this.loadingType = 2;
						}
						uni.hideLoading();

						if (type === "Refresh") {
							uni.stopPullDownRefresh(); // 停止刷新
						}
					})
			},
			toGoodsInfo: function(itemid) {
				let relation_id = this.$queue.getData("relation_id");
				if (relation_id) {
					uni.navigateTo({
						url: "/pages/detail/goodsinfo?itemid=" + itemid + "&relation_id=" + relation_id,
					})
				} else {
					uni.navigateTo({
						url: "/pages/detail/goodsinfo?itemid=" + itemid,
					})
				}
			},
		},

		onReachBottom: function() {
			this.page = this.page + 1;
			this.loadCouponList();
		},
		onPullDownRefresh: function() {
			this.page = 1;
			this.min_id = 1;
			this.loadCouponList("Refresh");
		}
	}
</script>

<style>
	@import "../static/css/index.css";
</style>
